<?php
	require_once('environment.php');
	$temp->addSubMenu("Videos", "videos.php");
	$temp->addSubMenu("Photos", "photos.php");
	if($acc->isLogged()){
		$temp->addSubMenu("Moderate Videos", "videos.php?admin=mod");
		$temp->addSubMenu("Moderate Photos", "photos.php?admin=mod");
		$temp->addSubMenu("Change Media Page", "media.php?admin=change");
	}
	
	if(fixArr($_GET, "admin") != "change") {
		$temp->setTab(3);
		$temp->currentPage("Home >> Media");
		$temp->generate();
		$sql = $db->Execute("SELECT * FROM `monster`.`frontPage` WHERE `AutoInc` = ? LIMIT 1", array(3));
		if($sql->RecordCount() < 1) {
			print "Sorry, connection failure.<br />\nPlease inform the administrator about the problem.";
		}else {
			$row = $sql->FetchRow();
			print nl2br(stripslashes($row['Text']));
		}
	}else {
		if(!$acc->isLogged()) die(change_site("account.php"));
		$temp->setTab(3,4);
		$temp->currentPage("Home >> Media >> Change Media Page");
		$temp->generate();
		if(!fixArr($_POST, "change")) {
			$sql = $db->Execute("SELECT * FROM `monster`.`frontPage` WHERE `AutoInc` = ? LIMIT 1", array(3));
			if($sql->RecordCount() == 1) {
				$row = $sql->FetchRow();
				print "<form action=\"\" method=\"POST\">\n";
				print "<textarea name=\"change\" style=\"resize: none;\" rows=\"20\" cols=\"60\">{$row['Text']}</textarea><br />\n";
				print "<input type=\"submit\" value=\"Change\" /> <input type=\"reset\" value=\"Reset\" />\n";
				print "</form>\n";
			}else {
				die("We have encountered a connection error.<br />\nPlease try again later.");
			}
		}else {
			$change = stripslashes(fixArr($_POST, "change"));
			$db->Execute("UPDATE `monster`.`frontPage` SET `Text` = ? WHERE `AutoInc` = ? LIMIT 1", array($change, 3));
			print "The Media Page has been changed successfully.";
		}
	}
?>